home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / pcb-1.000 / pcb-1 / pcb-1.3 / rotate.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  6KB  |  195 lines

  1. /*
  2.  *                            COPYRIGHT
  3.  *
  4.  *  PCB, interactive printed circuit board design
  5.  *  Copyright (C) 1994,1995 Thomas Nau
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  *  Contact addresses for paper mail and Email:
  22.  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
  23.  *  Thomas.Nau@rz.uni-ulm.de
  24.  *
  25.  */
  26.  
  27. static    char    *rcsid = "$Header: rotate.c,v 2.1 94/09/28 14:27:01 nau Exp $";
  28.  
  29. /* functions used to rotate pins, elements ...
  30.  */
  31.  
  32. #include <stdlib.h>
  33.  
  34. #include "global.h"
  35.  
  36. #include "crosshair.h"
  37. #include "data.h"
  38. #include "draw.h"
  39. #include "misc.h"
  40. #include "rotate.h"
  41. #include "search.h"
  42. #include "select.h"
  43.  
  44. /* ---------------------------------------------------------------------------
  45.  * some local prototypes
  46.  */
  47. static    void    *RotateText(LayerTypePtr, TextTypePtr);
  48. static    void    *RotateElementName(ElementTypePtr);
  49. static    void    RotateArcLowLevel(ArcTypePtr, Position, Position, BYTE);
  50.  
  51. /* ----------------------------------------------------------------------
  52.  * some local identifiers
  53.  */
  54. static    Position            CenterX,    /* center of rotation */
  55.                             CenterY;
  56. static    BYTE                Number;        /* number of rotations */
  57. static    ObjectFunctionType    RotateFunctions = {
  58.     NULL,
  59.     RotateText,
  60.     NULL,
  61.     NULL,
  62.     NULL,
  63.     RotateElementName,
  64.     NULL,
  65.     NULL };
  66.  
  67. /* ---------------------------------------------------------------------------
  68.  * rotates a line in 90 degree steps
  69.  */
  70. void RotateLineLowLevel(LineTypePtr Line, Position X, Position Y, BYTE Number)
  71. {
  72.     ROTATE(Line->X1, Line->Y1, X, Y, Number);
  73.     ROTATE(Line->X2, Line->Y2, X, Y, Number);
  74.  
  75. }
  76.  
  77. /* ---------------------------------------------------------------------------
  78.  * rotates a text in 90 degree steps 
  79.  * only the bounding box is rotated, text rotation itself
  80.  * is done by the drawing routines
  81.  */
  82. void RotateTextLowLevel(TextTypePtr Text, Position X, Position Y, BYTE Number)
  83. {
  84.     RotateBoxLowLevel(&Text->BoundingBox, X, Y, Number);
  85.     ROTATE(Text->X, Text->Y, X, Y, Number);
  86.  
  87.         /* set new direction, 0..3,
  88.          * 0-> to the right, 1-> straight up,
  89.          * 2-> to the left, 3-> straight down
  90.          */
  91.     Text->Direction = ((Text->Direction +Number) & 0x03);
  92. }
  93.  
  94. /* ---------------------------------------------------------------------------
  95.  * rotates a polygon in 90 degree steps
  96.  */
  97. void RotatePolygonLowLevel(PolygonTypePtr Polygon,
  98.     Position X, Position Y, BYTE Number)
  99. {
  100.     POLYGONPOINT_LOOP(Polygon,
  101.         ROTATE(point->X, point->Y, X, Y, Number);
  102.     );
  103.     RotateBoxLowLevel(&Polygon->BoundingBox, X, Y, Number);
  104. }
  105.  
  106. /* ---------------------------------------------------------------------------
  107.  * rotates a text object and redraws it
  108.  */
  109. static void *RotateText(LayerTypePtr Layer, TextTypePtr Text)
  110. {
  111.     EraseText(Text);
  112.     RotateTextLowLevel(Text, CenterX, CenterY, Number);
  113.     DrawText(Layer, Text);
  114.     return(Text);
  115. }
  116.  
  117. /* ---------------------------------------------------------------------------
  118.  * rotates an arc
  119.  */
  120. static void RotateArcLowLevel(ArcTypePtr Arc,
  121.     Position X, Position Y,
  122.     BYTE Number)
  123. {
  124.     Dimension    save;
  125.  
  126.         /* add Number*90 degrees to the startangle and check for overflow */
  127.     Arc->StartAngle = (Arc->StartAngle +Number*90) % 360;
  128.     ROTATE(Arc->X, Arc->Y, X, Y, Number);
  129.  
  130.         /* now change width and height */
  131.     if (Number == 1 || Number == 3)
  132.     {
  133.         save = Arc->Width;
  134.         Arc->Width = Arc->Height;
  135.         Arc->Height = save;
  136.     }
  137. }
  138.  
  139. /* ---------------------------------------------------------------------------
  140.  * rotate an element in 90 degree steps
  141.  */
  142. void RotateElementLowLevel(ElementTypePtr Element,
  143.     Position X, Position Y,
  144.     BYTE Number)
  145. {
  146.     ELEMENTLINE_LOOP(Element, RotateLineLowLevel(line, X, Y, Number););
  147.     PIN_LOOP(Element, ROTATE_PIN_LOWLEVEL(pin, X, Y, Number););
  148.     ARC_LOOP(Element, RotateArcLowLevel(arc, X, Y, Number););
  149.     ROTATE(Element->MarkX, Element->MarkY, X, Y, Number);
  150.     RotateBoxLowLevel(&Element->BoundingBox, X, Y, Number);
  151.     RotateTextLowLevel(&CANONICAL_TEXT(Element), X, Y, Number);
  152.     RotateTextLowLevel(&NAMEONPCB_TEXT(Element), X, Y, Number);
  153. }
  154.  
  155. /* ----------------------------------------------------------------------
  156.  * rotates the name of an element
  157.  */
  158. static void *RotateElementName(ElementTypePtr Element)
  159. {
  160.     EraseElementName(Element);
  161.     RotateTextLowLevel(&CANONICAL_TEXT(Element), CenterX, CenterY, Number);
  162.     RotateTextLowLevel(&NAMEONPCB_TEXT(Element), CenterX, CenterY, Number);
  163.     DrawElementName(Element);
  164.     return(Element);
  165. }
  166.  
  167. /* ---------------------------------------------------------------------------
  168.  * rotates a box in 90 degree steps 
  169.  */
  170. void RotateBoxLowLevel(BoxTypePtr Box,
  171.     Position X, Position Y, BYTE Number)
  172. {
  173.     ROTATE(Box->X1, Box->Y1, X, Y, Number);
  174.     ROTATE(Box->X2, Box->Y2, X, Y, Number);
  175.     Box->X1 = MIN(Box->X1, Box->X2);
  176.     Box->Y1 = MIN(Box->Y1, Box->Y2);
  177.     Box->X2 = MAX(Box->X1, Box->X2);
  178.     Box->Y2 = MAX(Box->Y1, Box->Y2);
  179. }
  180.  
  181. /* ----------------------------------------------------------------------
  182.  * rotates an objects at the cursor position as identified by its ID
  183.  * the center of rotation is determined by the current cursor location
  184.  */
  185. void RotateObject(int Type, void *Ptr1, void *Ptr2,
  186.     Position X, Position Y, BYTE Steps)
  187. {
  188.         /* setup default  global identifiers */
  189.     CenterX = X;
  190.     CenterY = Y;
  191.     Number = Steps;
  192.     ObjectOperation(&RotateFunctions, Type, Ptr1, Ptr2);
  193. }
  194.  
  195.